﻿using EFBase;
using Syc.Domain;
using Syc.Code;

namespace Syc.Repository
{
    public class UserRepository : RepositoryBase<UsersEntity>, IUserRepository
    {
        public void DeleteForm(string keyValue)
        {
            using (var db = new RepositoryBase().BeginTrans())
            {
                db.Delete<UsersEntity>(t => t.Id == keyValue);
                db.Commit();
            }
        }

        public void SubmitForm(UsersEntity userEntity, string keyValue)
        {
            using (var db = new RepositoryBase().BeginTrans())
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    db.Update(userEntity);
                }
                else
                {
                    userEntity.PassWord = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userEntity.PassWord, 32).ToLower(), "").ToLower(), 32).ToLower();
                    db.Insert(userEntity);
                }
                db.Commit();
            }
        }
    }
}
